import api from './http'

// 参数转化 对象转成url参数
export const paramsConversion = (data) => {
  let url = '?'
  for (const key in data) {
    if (data[key] !== undefined && data[key] !== null) {
      url += `${key}=${data[key]}&`
    }
  }
  return url.slice(0, -1)
}

/**
 * @description 获取官网首页数据
 * @returns
 */
export const selectOfficialWebsiteHomePageDataDto = () => {
  return api
    .get('/zcloak-rest/officialWebsiteHomePageData/selectOfficialWebsiteHomePageDataDto')
    .then((response) => {
      return response.data
    })
    .catch((error) => {
      console.error('Error fetching official website home page data:', error)
      throw error
    })
}
/**
 * @description 获取交易汇总区域数据
 * @returns
 */
export const selectTransactionSumZoneDtoList = () => {
  return api
    .get('/zcloak-rest/transactionSumZone/selectTransactionSumZoneDtoList')
    .then((response) => {
      return response.data
    })
    .catch((error) => {
      console.error('Error fetching transaction sum zone data:', error)
      throw error
    })
}

export const pageLiveTransactionDto = (params) => {
  return api
    .get('/zcloak-rest/liveTransaction/pageLiveTransactionDto' + paramsConversion(params))
    .then((response) => {
      return response.data
    })
    .catch((error) => {
      console.error('Error fetching transaction sum zone data:', error)
      throw error
    })
}
